<?php

namespace app\api\logic;


use app\common\logic\BaseLogic;
use app\common\model\goods\GoodsCategory;

class GoodsCategoryLogic extends BaseLogic
{
    /**
     * @notes 其它分类列表
     * @param $id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/3/29 3:15 下午
     */
    public function otherLists($id)
    {
        if (!$id) {
            return [];
        }

        $category = GoodsCategory::where(['id'=>$id])->order(['sort'=>'desc','id'=>'asc'])->findOrEmpty()->toArray();
        if (!$category) {
            return [];
        }

        if ($category['level'] == 2) {
            $category = GoodsCategory::where(['id'=>$category['pid']])->order(['sort'=>'desc','id'=>'asc'])->findOrEmpty()->toArray();
        }

        $sons = GoodsCategory::where(['pid'=>$category['id']])->order(['sort'=>'desc','id'=>'asc'])->select()->toArray();
        return ['info'=>$category,'sons'=>$sons];
    }
}